/**
 * DiggApiNet - Digg API .NET Wrapper
 * 
 * Author: Sean Hickey
 * Link: http://www.headzoo.com/digg_api_net
 * License: GPL v2 ( http://www.gnu.org/licenses/gpl.txt )
 */
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace DiggApiNet
{
    public class DiggComment : DiggReturnBase
    {
        public DateTime     Date
        {
            get
            {
                XmlNode node = (XmlNode)_dict["comment"];
                return GetDateTimeFromTimeStamp(node.Attributes["date"].InnerText);
            }
        }
        public long         Story
        {
            get
            {
                XmlNode node = (XmlNode)_dict["comment"];
                return long.Parse(node.Attributes["story"].InnerText);
            }
        }
        public long         Id
        {
            get
            {
                XmlNode node = (XmlNode)_dict["comment"];
                return long.Parse(node.Attributes["id"].InnerText);
            }
        }
        public int          Up
        {
            get
            {
                XmlNode node = (XmlNode)_dict["comment"];
                return int.Parse(node.Attributes["up"].InnerText);
            }
        }
        public int          Down
        {
            get
            {
                XmlNode node = (XmlNode)_dict["comment"];
                return int.Parse(node.Attributes["down"].InnerText);
            }
        }
        public int          Replies
        {
            get
            {
                XmlNode node = (XmlNode)_dict["comment"];
                return int.Parse(node.Attributes["replies"].InnerText);
            }
        }
        public long         ReplyTo
        {
            get
            {
                XmlNode node = (XmlNode)_dict["comment"];
                if (node.Attributes["replyto"] == null) {
                    return -1;
                }
                return long.Parse(node.Attributes["replyto"].InnerText);
            }
        }
        public string       User
        {
            get
            {
                XmlNode node = (XmlNode)_dict["comment"];
                return node.Attributes["user"].InnerText;
            }
        }
        public string       Comment
        {
            get
            {
                XmlNode node = (XmlNode)_dict["comment"];
                return node.InnerText;
            }
        }

        public DiggComment(XmlDocument xml_doc) : this(xml_doc.SelectSingleNode("events").SelectSingleNode("comment"))
        {
            
        }
        public DiggComment(XmlNode node) : base(node)
        {

        }

        public override string ToString()
        {
            return Comment;
        }
        public string Get()
        {
            StringBuilder str = new StringBuilder(200);
            str.Append("Date: ").Append(Date.ToString("r")).Append(" ");
            str.Append("Story: ").Append(Story.ToString()).Append(" ");
            str.Append("Id: ").Append(Id.ToString()).Append(" ");
            str.Append("Up: ").Append(Up.ToString()).Append(" ");
            str.Append("Down: ").Append(Down.ToString()).Append(" ");
            str.Append("Replies: ").Append(Replies.ToString()).Append(" ");
            str.Append("ReplyTo: ").Append(ReplyTo.ToString()).Append(" ");
            str.Append("User: ").Append(User).Append(" ");
            str.Append("Comment:\r\n").Append(Comment).Append("\r\n\r\n");
            return str.ToString();
        }
    }
}
